package com.upcoming.dbdemo.service;

import com.upcoming.dbdemo.entity.dto.UserDTO;
import com.upcoming.dbdemo.entity.po.UserPo;
import com.upcoming.dbdemo.repository.UserDao;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service("userService")
@Log4j2
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public void addUser(UserDTO userDTO) {
        UserPo userPo = new UserPo();
        userPo.setUserId(userDTO.getId());
        userPo.setUserName(userDTO.getUserName());
        userPo.setAge(userDTO.getAge());
        this.userDao.addUser(userPo);
        log.info("info");
        log.error("error");
        log.debug("debug");
        log.warn("warn");
        log.trace("trace");
        log.fatal("fatal");
    }

    @Override
    public UserDTO getUser(long id) {
        UserPo userPo = this.userDao.getUser(id);
        UserDTO userDTO = new UserDTO();
        userDTO.setId(userPo.getUserId());
        userDTO.setUserName(userPo.getUserName());
        userDTO.setAge(userPo.getAge());
        log.info("info");
        log.error("error");
        log.debug("debug");
        log.warn("warn");
        log.trace("trace");
        log.fatal("fatal");
        return userDTO;
    }
}
